package com.xtedu.examproject.controller;

import jakarta.servlet.ServletConfig;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;

public class ConfigContextServlet extends HttpServlet {
    private String locale;
    @Override
    public void init(ServletConfig config){
        try {
            PrintWriter utf8Out = new PrintWriter(new OutputStreamWriter(System.out, "UTF-8"), true);
            String name=config.getServletName();
            locale=config.getInitParameter("defaultLocale");
            System.out.println(name+":"+locale);
            Enumeration<String>  paraNames=config.getInitParameterNames();
            while(paraNames.hasMoreElements()){
                String pname=paraNames.nextElement();
                String value=config.getInitParameter(pname);
                utf8Out.println("存在name:"+pname+"---值:"+value);
            }
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }

    }
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

        response.getWriter().println(locale);
    }
    public void destroy(){

    }

}
